package hypeerweb;
import java.util.*;

import proxyCommand.ObjectDB;

import visitor.BroadcastShiftNeighbors;
import visitor.Parameters;

public class ConnectionsRemover extends ConnectionsModifier {
	public ConnectionsRemover() {}
	
	public void refreshConnections(Node modifyingNode) {
		//removing cap node
        if (modifyingNode.getFold() != null && modifyingNode.getFold().getWebId().getValue() == 0) {
        	BroadcastShiftNeighbors broadcast = new BroadcastShiftNeighbors();
        	Parameters p = new Parameters();
        	p.set("shift", "left");
        	broadcast.visit(modifyingNode, p);
        }
        //ObjectDB.getSingleton().dump();
	}
	
	public void modifyConnection(Node target, NodeDelegate connection, Node modifyingNode, Node replacingNode) {
		if(connection != null) {
			connection.remove(modifyingNode);
		}
	}
	
	public ArrayList<NodeDelegate> getAllConnections(Node target, Node deletionNode) {
		return deletionNode.getConnections().getAllConnections();
	}
	
	public Node getModifyingNode(Node startingNode) {
		return Range.getNodeRange(startingNode).getLowerBound();
	}
	
	public void setWebId(Node node, Node modifyingNode, Node replacingNode) {}
	
	public void modifyConnections(Node target, Node modifyingNode, Node replacingNode) {}
	
	public Node finalizeConnections(Node target, Node modifyingNode, Node replacingNode) {
		modifyingNode.setConnections(new Connections(modifyingNode));
		//ObjectDB.getSingleton().dump();

		return modifyingNode;
	}
}
